﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace MVC_da.Models.Database
{
    public partial class newsContext : DbContext
    {
        public newsContext()
        {
        }

        public newsContext(DbContextOptions<newsContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Category> Categories { get; set; }
        public virtual DbSet<Xinwen> Xinwens { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=news;Integrated Security=SSPI");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Category>(entity =>
            {
                entity.HasKey(e => e.Cateid);

                entity.ToTable("category");

                entity.Property(e => e.Cateid)
                    .ValueGeneratedNever()
                    .HasColumnName("cateid");

                entity.Property(e => e.Catename)
                    .IsRequired()
                    .HasMaxLength(20)
                    .HasColumnName("catename");
            });

            modelBuilder.Entity<Xinwen>(entity =>
            {
                entity.HasKey(e => e.Nno)
                    .HasName("PK_new");

                entity.ToTable("xinwen");

                entity.Property(e => e.Nno)
                    .ValueGeneratedNever()
                    .HasColumnName("nno");

                entity.Property(e => e.Cateid).HasColumnName("cateid");

                entity.Property(e => e.Ncontent)
                    .IsRequired()
                    .HasMaxLength(200)
                    .HasColumnName("ncontent");

                entity.Property(e => e.Npictureurl)
                    .IsRequired()
                    .HasMaxLength(20)
                    .HasColumnName("npictureurl");

                entity.Property(e => e.Nsource)
                    .IsRequired()
                    .HasMaxLength(20)
                    .HasColumnName("nsource");

                entity.Property(e => e.Ntime)
                    .HasColumnType("datetime")
                    .HasColumnName("ntime");

                entity.Property(e => e.Ntitle)
                    .IsRequired()
                    .HasMaxLength(20)
                    .HasColumnName("ntitle");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
